package domeCloneable;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-05-27
 * Time: 11:11
 */

class Money implements Cloneable{
    public double m;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Person implements Cloneable{
    public String name;
    public Money money = new Money();

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", money=" + money.m +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person person = (Person) super.clone();
        person.money = (Money) this.money.clone();
        return person;
    }
}
public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person();
        person1.name = "qwer";
        person1.money.m = 12.25;
        Person person2 = (Person) person1.clone();
        person1.money.m = 99;
        System.out.println(person1);
        System.out.println(person2);
    }
}
